<!DOCTYPE html>
<html lang="en">
<head>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no,email=no" name="format-detection">
    <meta name="wap-font-scale" content="no">
    <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><?=$title?></title>
    <link rel="stylesheet" href="/mobile/css/reset.css">
    <link rel="stylesheet" href="/mobile/css/mui.min.css">
    <link rel="stylesheet" href="/mobile/css/dropload.css">
    <script src="/mobile/js/flexible_css.debug.js"></script>
    <script src="/mobile/js/flexible.debug.js"></script>
    <link rel="stylesheet" href="/mobile/css/main_train.css">

</head>
<body style="height: auto;">
<div id="back-btn-wrap">
    <a class="back-btn" href="javascript:history.go(-1)"></a>论坛详情<a href="/mobile/society/add" class="btn-edit mui-icon mui-icon-compose"></a>
</div>

<div class="content-main" id="fmDetail">
    <h1 class="title"></h1>
    <div class="top clearfix">
    </div>
    <p class="fm-content">
    </p>
    <div class="fm-pic-wrap">

    </div>

    <div class="comments-wrap">
        <p class="tips">全部回复</p>
        <ul class="comments-list">
        </ul>
    </div>

</div>

<div class="send-tool-wrap">
    <textarea name=""></textarea>
    <span class="msg-send-btn">发送</span>
</div>

<script src="/mobile/js/jquery.min.js"></script>
<script src="/mobile/js/dropload.js"></script>
<script src="/mobile/js/common.js"></script>
<script src="/mobile/js/mui.min.js"></script>
<script src="/mobile/js/jrrpc.js"></script>
<script src="/mobile/js/autosize.js"></script>

<script>
    $(function() {
        mui.init();
        var token = iService.getAppParam();
        $('textarea').autosize();
        iService.iosInput();
        var sid = iService.getQueryString('sid');
        var page = 2;
        var commentsListWrap = $('.comments-list');
//        评论列表
        function getSubComment(page,me){
            var param = {
                postData: 'Society/commentLists',
                data: {
                    page: page,
                    sid:sid
                }
            };
            $.extend(param.data,token);
            $.JsonRpc(param,function(result){
                console.log(result);
                if(!commentsListWrap.attr('data-page')){
                    commentsListWrap.attr('data-page',result.data.count);
                }
                var data = result.data.lists;
                $.each(data,function(i){
                    $(
                            '<li>'+
                            '<span class="fl avatar" style="background: url('+data[i].avatar+') center center no-repeat; background-size: cover;"></span>'+
                            '<div class="fl info">'+
                            '<p>'+data[i].nickname+'</p>'+
                            '<span>'+data[i].createtime+'</span>'+
                            '</div>'+
                            '<p class="content-sub">'+data[i].content+'</p>'+
                            '</li>'
                    ).appendTo('.comments-list');
                });
                if(me){
                    me.resetload();
                }
            },me);
        }

        var param = {
            postData:'Society/detailed',
            data: {
                sid:sid
            }
        };

        $.extend(param.data,token);
//        主页面
        $.JsonRpc(param,function(result){
            console.log(result);
            var data = result.data;

            $('.title').html(data.society.title);
            $(
                '<span class="fl avatar" style="background: url('+data.society.avatar+') center center no-repeat; background-size: cover;"></span>'+
                '<div class="fl info">'+
                '<p>'+data.society.nickname+'</p>'+
                '<span>'+data.society.createtime.slice(0,16)+'</span>'+
                '</div>'+
                '<i class="fr comment-num">'+data.society.comment+'</i>'
            ).appendTo('.top');

            $(".fm-content").html(data.society.content);
            if(data.society.images){
                var img_arr = String(data.society.images).split(',');
                var img_html = "";
                $.each(img_arr,function(i){
                    img_html += '<img src="'+img_arr[i]+'" alt="">'
                });
                $('.fm-pic-wrap').html(img_html);
            }
//            首次加载评论
            var com_html='';
            if(data.comment.length){
                $.each(data.comment,function(i){
                    com_html+=
                            '<li>'+
                            '<span class="fl avatar" style="background: url('+data.comment[i].avatar+') center center no-repeat; background-size: cover;"></span>'+
                            '<div class="fl info">'+
                            '<p>'+data.comment[i].nickname+'</p>'+
                            '<span>'+data.comment[i].createtime.slice(0,16)+'</span>'+
                            '</div>'+
                            '<p class="content-sub">'+data.comment[i].content+'</p>'+
                            '</li>';
                });
                $(com_html).appendTo('.comments-list');
            }else {
                com_html = '<li class="dropload-noData">暂无数据</li>';
                $(com_html).appendTo('.comments-list');
                return false;
            }
//            下拉加载
            $('.comments-wrap').dropload({
//                滑动区域
                scrollArea: window,
//                autoLoad:false,
                distance: 50,
                threshold: "",
                domDown: {
                    domClass: "dropload-down",
                    domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
                    domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
                    domNoData: '<div class="dropload-noData">已加载全部</div>'
                },
                loadDownFn: function(me){
                    if(page==1){
                        getSubComment(page,me);
                        page +=1;
                    }else if(page<=Math.ceil(commentsListWrap.attr('data-page')/3)
                    ){
                        getSubComment(page,me);
                        page +=1;
                    }else {
                        me.lock();//没有更多数据
                        me.noData();//没有更多数据
                        me.resetload();
                    }
                }
            });

        });
//        回复帖子
        mui('.send-tool-wrap').on('tap','.msg-send-btn',function(){
            var content = $('textarea').val();
            $('textarea').val('');
            if(!content){
                mui.alert('回复内容不能为空');
                return false;
            }
            var req = {
                postData:'Society/commentPost',
                data:{
                    sid:sid,
                    content:content
                }
            };
            $.extend(req.data,token);
            $.JsonRpc(req,function(result){
//              成功以后放到第一条
                /*$(
                    '<li>'+
                    '<span class="fl avatar" style="background: url('+result.data.avatar+') center center no-repeat; background-size: cover;"></span>'+
                    '<div class="fl info">'+
                    '<p>'+result.data.nickname+'</p>'+
                    '<span>'+result.data.createtime+'</span>'+
                    '</div>'+
                    '<p class="content-sub">'+result.data.content+'</p>'+
                    '</li>'
                ).prependTo('.comments-list');*/
              mui.toast(result.data.message);
                setTimeout(function(){
                    window.location.reload();
                },2000)
            });
        });
        $.get('https://www.wzxaini9.cn/api/flow/index/id/11', function (data) {
            console.log($.parseJSON(data));
        })
    });
</script>
</body>
</html>












